package com.ruoyi.web.controller.yusuan;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.yusuan.domain.YsMedicalRisk;
import com.ruoyi.yusuan.service.IYsMedicalRiskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 医疗风险专项支出表Controller
 *
 * @author mzh
 * @date 2021-01-13
 */
@Controller
@RequestMapping("/yusuan/risk")
public class YsMedicalRiskController extends BaseController {
    private String prefix = "yusuan/risk";

    @Autowired
    private IYsMedicalRiskService ysMedicalRiskService;

    @RequiresPermissions("yusuan:risk:view")
    @GetMapping()
    public String risk() {
        return prefix + "/risk";
    }

    /**
     * 查询医疗风险专项支出表列表
     */
    @RequiresPermissions("yusuan:risk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YsMedicalRisk ysMedicalRisk) {
        startPage();
        List<YsMedicalRisk> list = ysMedicalRiskService.selectYsMedicalRiskList(ysMedicalRisk);
        return getDataTable(list);
    }

    /**
     * 导出医疗风险专项支出表列表
     */
    @RequiresPermissions("yusuan:risk:export")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YsMedicalRisk ysMedicalRisk) {
        List<YsMedicalRisk> list = ysMedicalRiskService.selectYsMedicalRiskList(ysMedicalRisk);
        ExcelUtil<YsMedicalRisk> util = new ExcelUtil<YsMedicalRisk>(YsMedicalRisk.class);
        return util.exportExcel(list, "risk");
    }

    /**
     * 新增医疗风险专项支出表
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存医疗风险专项支出表
     */
    @RequiresPermissions("yusuan:risk:add")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YsMedicalRisk ysMedicalRisk) {
        /*默认添加状态为新建*/
        ysMedicalRisk.setStates("1");
        return toAjax(ysMedicalRiskService.insertYsMedicalRisk(ysMedicalRisk));
    }

    /**
     * 修改医疗风险专项支出表
     */
    @GetMapping("/edit/{reskId}")
    public String edit(@PathVariable("reskId") Long reskId, ModelMap mmap) {
        YsMedicalRisk ysMedicalRisk = ysMedicalRiskService.selectYsMedicalRiskById(reskId);
        mmap.put("ysMedicalRisk", ysMedicalRisk);
        return prefix + "/edit";
    }

    /**
     * 修改保存医疗风险专项支出表
     */
    @RequiresPermissions("yusuan:risk:edit")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YsMedicalRisk ysMedicalRisk) {
        return toAjax(ysMedicalRiskService.updateYsMedicalRisk(ysMedicalRisk));
    }

    /**
     * 删除医疗风险专项支出表
     */
    @RequiresPermissions("yusuan:risk:remove")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ysMedicalRiskService.deleteYsMedicalRiskByIds(ids));
    }

    /**
     * 提交医疗风险专项支出表
     */
    @RequiresPermissions("yusuan:risk:commit")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.COMMIT)
    @PostMapping("/commit")
    @ResponseBody
    public AjaxResult commit(String ids) {
        return toAjax(ysMedicalRiskService.commitYsMedicalRiskByIds(ids));
    }

    /**
     * 撤回医疗风险专项支出表
     */
    @RequiresPermissions("yusuan:risk:chehui")
    @Log(title = "医疗风险专项支出表", businessType = BusinessType.COMMIT)
    @PostMapping("/chehui")
    @ResponseBody
    public AjaxResult chehui(String ids) {
        return toAjax(ysMedicalRiskService.chehuiYsMedicalRiskByIds(ids));
    }
}
